<template>
    <div>
      <el-form :inline="true" class="demo-form-inline"  >
          <el-row>
              <p><b>首页</b>/住院部/护士站:科室病人</p>
          </el-row>
  <br>
          <el-row>
              <el-col :span="3">  
              <el-form-item >
                  <el-select placeholder="请选择医生" v-model="param.workId">
                  <el-option :label="work.wkName" :key="work.id" :value="work.id" v-for="work in WorkesList"></el-option>
                  </el-select>
              </el-form-item>
              </el-col> 
  
              <el-col :span="3">
                  <el-form-item >
                  <el-input placeholder="请输入病人" v-model="param.patientName"></el-input>
                  </el-form-item>
              </el-col>
  
              <el-col :span="3">
                  <el-form-item >
                  <el-select placeholder="请选择病床" v-model="param.bedId">
                  <el-option :label="bed.bno" :key="bed.id" :value="bed.id" v-for="bed in allBedList"></el-option>
                  </el-select>
                  </el-form-item>
              </el-col>
  
              <el-col :span="3" >
                  <el-form-item>
                      <el-button type="primary" @click="queryAllInpatientBtn">查询</el-button>
                      <el-button @click="resetForm">清空</el-button>
                  </el-form-item>
              </el-col>
          </el-row> 
      </el-form>
  
      <el-row>
          <el-table
              :data="tableData"
              style="width: 100%"
              >
              <el-table-column
              prop="patientName"
              label="病人"
              >
              </el-table-column>
              <el-table-column
              prop="departmentName"
              label="部门"
              >
              </el-table-column>
              <el-table-column
              prop="workerName"
              label="医生"
              >
              </el-table-column>
              <el-table-column
              prop="bedNumber"
              label="病床"
              >
              </el-table-column>
              <el-table-column
              prop="requestTime"
              label="入院时间"
              >
              </el-table-column>
             
              <el-table-column
              fixed="right"
              label="操作"
              width="400px"
              >
              <template slot-scope="scope">
                  <el-button type="danger" @click="addnursing(scope.row.patientId,scope.row.workerId)" >
                  添加记录
                  </el-button>
                  <el-button type="success" @click="queryNursingRecord(scope.row.patientId,scope.row.workerId)">
                  查看记录
                  </el-button>
                  <el-button type="primary" @click="OrdersList(scope.row.patientId)">
                  查看医嘱
                  </el-button>
              </template>
              </el-table-column>
          </el-table>
      </el-row>
  
      <el-row>
        <el-col>
          <el-pagination
                  background
                  :page-sizes="[3, 5, 10, 30]"
                  :page-size="pageSize"
                  :current-page="pageNum"
                  layout="prev, pager, next, total, sizes"
                  :total="total"
                  @next-click="nextPage"
                  @prev-click="prevPage"
                  @current-change="changePage"
                  @size-change="changeSize"
                  >
          </el-pagination>
        </el-col>
      </el-row>
  
      <!-- 添加护理记录弹窗开始 -->
      <el-dialog title="添加护理记录" :visible.sync="nursingForm">
        <el-form label-position="right" label-width="100px">

            <el-form-item >
            <span slot="label">
                <span style="color: red">*</span>
                <span>体温</span>
            </span>
            <el-input v-model="AddNursingInfo.nrTemperature"></el-input>
            </el-form-item>

            <el-form-item>
            <span slot="label">
                <span style="color: red">*</span>
                <span>血压</span>
            </span>
            <el-input v-model="AddNursingInfo.nrBloodPressure"></el-input>
            </el-form-item>
            <el-form-item>
            <span slot="label">
                <span style="color: red">*</span>
                <span>心率</span>
            </span>
            <el-input v-model="AddNursingInfo.nrPulse"></el-input>
            </el-form-item>
            <el-form-item>
            <span slot="label">
                <span style="color: red">*</span>
                <span>护理记录</span>
            </span>
            <el-input type="textarea" v-model="AddNursingInfo.nrContent"></el-input>
            </el-form-item>
            
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="nursingForm = false">取 消</el-button>
            <el-button type="primary" @click="saveAddNursing">确 定</el-button>
        </div>
      </el-dialog>
      <!-- 添加护理记录弹窗结束 -->

      <!-- 查看护理记录弹窗开始 -->
      <el-dialog title="护理记录" :visible.sync="nursingRecordForm" style="text-align: center;">
        <el-table v-if="!loading" :data="gridData">
            <el-table-column property="workerName" label="护理医生"></el-table-column>
            <el-table-column property="nrTemperature" label="温度"></el-table-column>
            <el-table-column property="nrBloodPressure" label="血压"></el-table-column>
            <el-table-column property="nrPulse" label="心率"></el-table-column>
            <el-table-column property="nrDate" label="护理日期"></el-table-column>
            <el-table-column property="nrContent" label="内容"></el-table-column>
        </el-table>
        <div v-else v-loading="loading" element-loading-spinner="el-icon-loading"></div>
        <div slot="footer" class="dialog-footer">
            <el-button @click="nursingRecordForm = false">退出</el-button>
        </div>
      </el-dialog>
      <!-- 查看护理记录弹窗结束 -->

      <!-- 查看医嘱弹窗开始 -->
      <el-dialog title="查看医嘱" :visible.sync="OrdersListForm">
        <el-table v-if="!loading" :data="OrderData">
            <el-table-column property="doCaseName" label="病人"></el-table-column>
            <el-table-column property="doWorkerName" label="医生"></el-table-column>
            <el-table-column property="doContent" label="医嘱"></el-table-column>
            <el-table-column property="doDoWorkerName" label="执行护士"></el-table-column>
            <el-table-column fixed="right" label="操作">
                <template slot-scope="scope">
                    <el-button v-if="scope.row.doStatus==0" type="success"  @click="startOrder(scope.row.id)" >执行医嘱</el-button>
                    <el-button v-if="scope.row.doStatus==1" type="info" disabled>
                    完成医嘱
                    </el-button>
                </template>
            </el-table-column>
        </el-table>

        <div v-else v-loading="loading" element-loading-spinner="el-icon-loading"></div>
        
        <div slot="footer" class="dialog-footer">
            <el-button @click="OrdersListForm = false">退出</el-button>
        </div>
      </el-dialog>
      <!-- 查看医嘱弹窗结束 -->
  </div>
  </template>
  
  <script>

  export default {
    data() {
      return {
          tableData: [],

          pageSize:5,
          pageNum:1,
          total:0,
          param:{
          },
          nursingForm:false,
          nursingRecordForm:false,
          OrdersListForm:false,
          gridData:[],
          OrderData:[],
          WorkesList:[],
          allBedList:[],
          AddNursingInfo:{},
          loading: true,
      }
    },
  
    methods: {
      queryAllDoctor(){
        this.$axios.get('api/nurse/queryAllDoctor').then(resp=>{
          this.WorkesList=resp.data.data
        })
      },

      queryAllBed(){
      this.$axios.get("api/nurse/queryAllBed").then(resp=>{
        if(resp.data.code==200){
          this.allBedList=resp.data.data
        }
      })
    },

      queryAllInpatientBtn(){
        let pageData={}
        pageData.pageSize=this.pageSize
        pageData.pageNum=this.pageNum
        pageData.param=this.param
        this.$axios.post('api/nurse/queryAllInpatient',pageData).then(resp=>{
          if(resp.data.code==200){
            
            this.tableData=resp.data.data.list
            this.total=resp.data.data.total
            // console.log(resp.data)
          }
        })
      },

      addnursing(patientId,workerId){
        this.nursingForm=true
        this.AddNursingInfo.nrCaseId=patientId
        this.AddNursingInfo.nrWorkerId=workerId
      },

      saveAddNursing(){
        this.$axios.post('api/nurse/saveAddNursing',this.AddNursingInfo).then(resp=>{
          if(resp.data.code==200){
            this.nursingForm=false
            this.$message({
                showClose: true,
                message: '添加护理成功',
                type: 'success'
            });
          }
        })
      },
      
      queryNursingRecord(patientId,workerId){
        this.loading=true
        this.nursingRecordForm=true
        let NursingRecord={}
        NursingRecord.nrCaseId=patientId
        NursingRecord.nrWorkerId=workerId
        this.$axios.post('api/nurse/queryNursingRecord',NursingRecord).then(resp=>{
          if(resp.data.code==200){

            this.gridData=resp.data.data
            setTimeout(()=>{
              this.loading=false
            },100)
          }
        })
      },

      OrdersList(patientId){
        this.loading=true
        this.OrdersListForm=true
        this.$axios.get('api/nurse/OrdersList/'+patientId).then(resp=>{
          if(resp.data.code==200){
            // console.log(resp.data)
            this.OrderData=resp.data.data
            setTimeout(()=>{
              this.loading=false
            },100)
          }
        })
      },

      startOrder(id){
        // 传入医嘱表的id，写入执行护士(登录账号的护士)，修改状态
        this.$axios.get('api/nurse/startOrder/'+id).then(resp=>{
          if(resp.data.code=200){
            this.OrdersListForm=false
            this.$message({
                showClose: true,
                message: '添加护理成功',
                type: 'success'
            });
          }
        })
      },
  
      //下一页方法
      nextPage(val){
                      //回调参数val,val等于当前页码
                      this.pageNum=val
                      this.queryAllInpatientBtn()
      },
      //上一页方法
      prevPage(val){
                      //回调参数val,val等0.于当前页码
                      this.pageNum=val
                      this.queryAllInpatientBtn()
      },
      changePage(val){
                      this.pageNum=val
                      this.queryAllInpatientBtn()
      },
      changeSize(val){
                      this.pageSize=val
                      this.pageNum=1
                      this.queryAllInpatientBtn()
      },
      resetForm(){
        this.param.workId=''
        this.param.patientName=''
        this.param.bedId=''
      },
  
    },
  
    created(){
      this.queryAllDoctor()
      this.queryAllBed()
      this.queryAllInpatientBtn()
    }
  }
  </script>
  
  <style scoped>
  
  </style>